﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Pixysoft.RTF.Core
{
    class RtfColorTable : IRtfColorTable
    {
        private readonly Color _defaultforecolor;
        private readonly Color _defaultbackcolor;

        private Color _backcolor;
        private Color _forecolor;

        private List<Color> _colortbl = new List<Color>();

        public RtfColorTable()
        {
            this._defaultforecolor = SystemColors.WindowText;
            this._defaultbackcolor = SystemColors.Window;

            this._backcolor = this._defaultbackcolor;
            this._forecolor = this._defaultforecolor;

            this._colortbl.Add(this._defaultforecolor);
            this._colortbl.Add(this._defaultbackcolor);
        }


        public void SetForeColor(int index)
        {
            index--;
            if (index >= 0 && index < this._colortbl.Count)
            {
                this.ForeColor = this._colortbl[index];
            }
            else if (index < 0)
            {
                this.ForeColor = this._colortbl[0];
            }
        }

        public int IndexOf(Color color)
        {
            if (!this._colortbl.Contains(color))
            {
                this._colortbl.Add(color);
            }
            int index = this._colortbl.IndexOf(color) + 1;

            return index;
        }


        public Color ForeColor
        {
            get
            {
                return _forecolor;
            }
            set
            {
                _forecolor = value;
            }
        }

        public Color BackColor
        {
            get
            {
                return _backcolor;
            }
            set
            {
                _backcolor = value;
            }
        }


        public Color DefaultBackColor
        {
            get
            {
                return _defaultbackcolor;
            }
        }

        public Color DefaultForeColor
        {

            get { return this._defaultforecolor; }
        }

        public Color[] ColorTableList
        {
            get
            {
                return this._colortbl.ToArray();
            }
        }
    }
}
